<include file="./Template/Admin/header.html" title="修改用户组" />
<body class="gray-bg">
<div class="wrapper wrapper-content animated fadeInRight">
    <div class="row">
        <div class="col-sm-12">
            <div class="ibox float-e-margins">
                <div class="ibox-title">
                    <h5>添加用户组</h5>
                </div>
                <div class="ibox-content">
                    <div class="row m-b-sm m-t-sm">
                        <div class="col-md-2">
                            <a href="{:U('Admin/group/index')}" class="btn btn-outline btn-primary">返回用户组列表</a>
                        </div>
                    </div>
                    <form class="form-horizontal m-t" id="editForm" action="{:U('Admin/group/Save')}">
                        <div class="form-group">
                            <label class="col-sm-3 control-label">用户组名称：</label>
                            <div class="col-sm-8">
                                <input id="title" name="title" class="form-control" type="text" value="{$arr.title}">
                                <input type="hidden" name="id" id="id" value="{$arr.id}">
                                <span class="help-block m-b-none"></span>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <label class="col-sm-3 control-label">状态：</label>
                            <div class="col-sm-8">
                                <input type="checkbox" class="js-switch form-control" value="1" name="status" id="status" <if condition="$arr.status eq 1"> checked</if>/>
                            </div>
                        </div>
                        <div class="hr-line-dashed"></div>
                        <div class="form-group">
                            <div class="col-sm-8 col-sm-offset-3">
                                <button class="btn btn-primary" type="submit">修改</button>
                            </div>
                        </div>
                    </form>
                </div>
            </div>
        </div>
    </div>
</div>
<script src="__ADMIN__js/jquery.min.js"></script>
<script src="__ADMIN__js/bootstrap.min.js"></script>
<script src="__ADMIN__js/plugins/layer.3/layer.js"></script>
<script src="__ADMIN__js/common.js"></script>
<script src="__ADMIN__js/content.min.js"></script>
<script src="__ADMIN__js/plugins/validate/jquery.validate.min.js"></script>
<script src="__ADMIN__js/plugins/validate/messages_zh.min.js"></script>
<script src="__ADMIN__js/plugins/switchery/switchery.js"></script>
<script>
    var elem = document.querySelector('.js-switch');
    var init = new Switchery(elem);

    $(function(){
        // 姓名格式验证
        jQuery.validator.addMethod("checkname", function(value, element) {
            if(/^[a-zA-Z0-9_-]{3,16}$/.test(value)) {
                return true;
            }else{
                return false;
            }
        }, "");
        $.validator.setDefaults({
            highlight: function (e) {
                $(e).closest(".form-group").removeClass("has-success").addClass("has-error")
            }, success: function (e) {
                e.closest(".form-group").removeClass("has-error").addClass("has-success")
            }, errorElement: "span", errorPlacement: function (e, r) {
                e.appendTo(r.is(":radio") || r.is(":checkbox") ? r.parent().parent().parent() : r.parent())
            }, errorClass: "help-block m-b-none", validClass: "help-block m-b-none"
        }), $().ready(function () {
            var e = "<i class='fa fa-times-circle'></i> ";

            $("#editForm").validate({
                rules: {
                    title: {required: true, minlength: 3, maxlength: 15, checkname: false}
                },
                messages: {
                    title: {required: e + "请输入用户组名称", minlength: e + "用户组名称长度必须大于3个汉字", maxlength: e + "用户组名称长度必须小于15个汉字", checkname: e + "用户组名称必须为3-15个汉字"}
                },
                submitHandler: function(form){
                    var objectArr = $(form).serializeArray();
                    var data = new Object();
                    $.each(objectArr,function(k,v){
                        data[v.name] = v.value;
                    });

                    $.post(
                        "{:U('Admin/group/Save')}",
                        data,
                        function(data){
                            if(data.status > 0){
                                common.error(data.msg);
                            }else{
                                common.success(data.msg,"{:U('Admin/group/index')}");
                            }
                        },
                        'JSON'
                    );
                }
            });
        });

    });
</script>
</body>
</html>
